package com.ruoyi.activiti.listener;

import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.finance.api.RemoteReciveOrderService;
import com.ruoyi.system.api.domain.finance.ReciveOrder;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @author wangenhao
 * @className ReciveOrderListener
 * @description
 * @date 2024-11-11 下午4:03
 **/
@Slf4j
public class ReciveOrderListener implements ExecutionListener {


    public void notify(DelegateExecution delegateExecution) {
        //封装财务收款单对象
        ReciveOrder reciveOrder = new ReciveOrder();
        reciveOrder.setOrderCode(delegateExecution.getProcessInstanceBusinessKey());
        Integer approvalResult = (Integer) delegateExecution.getVariable("approvalResult");
        String approvalOption = (String) delegateExecution.getVariable("approvalOption");
        //审核结果
        reciveOrder.setApprovalResult(approvalResult);
        reciveOrder.setApprovalOption(approvalOption);

        log.info("BuyBackReqListener notify reciveOrder:{}  approvalResult:{} approvalOption:{}", reciveOrder, approvalResult, approvalOption);
        //调用财务收款远程接口修改财务收款对象
        AjaxResult ajaxResult = SpringUtils.getBean(RemoteReciveOrderService.class).auditReciveOrderByOrderCode(reciveOrder);
        log.info("ajaxResult:{}", ajaxResult);
    }
}
